package com.ganmiao.web.supplier.controller.sys;

import com.ganmiao.resp.CommonResultRes;
import com.ganmiao.resp.MobBaseRes;
import com.ganmiao.resp.ResponseCode;
import com.ganmiao.server.sys.entity.SysDepartment;
import com.ganmiao.server.sys.query.SysDepartmentQuery;
import com.ganmiao.server.sys.service.SysDepartmentService;
import com.ganmiao.server.sys.validated.Add;
import com.ganmiao.server.sys.validated.Update;
import com.ganmiao.server.sys.vo.SysDepartmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门信息
 */
@Api(tags = "部门信息")
@Slf4j
@RestController
@RequestMapping("/sysDepartment")
public class SysDepartmentController {

    //部门信息
    @Autowired
    private SysDepartmentService sysDepartmentService;

    /**
     * 新增部门信息
     *
     * @param sysDepartment
     * @return
     */
    @ApiOperation("新增部门信息")
    @PostMapping("/addSysDepartment")
    public MobBaseRes addSysDepartment(@RequestBody @Validated(Add.class) SysDepartment sysDepartment) {
        return sysDepartmentService.addSysDepartment(sysDepartment) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "新增部门信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "新增部门信息失败");
    }

    /**
     * 删除部门信息
     *
     * @param departmentId
     * @return
     */
    @ApiOperation("删除部门信息")
    @PutMapping("/deleteSysDepartment/{departmentId}")
    public MobBaseRes deleteSysDepartment(@Validated @PathVariable Integer departmentId) {
        return sysDepartmentService.deleteSysDepartment(departmentId) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "删除部门信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "删除部门信息失败");
    }

    /**
     * 修改部门信息
     *
     * @param sysDepartment
     * @return
     */
    @ApiOperation("修改部门信息")
    @PutMapping("/updateSysDepartment")
    public MobBaseRes updateSysDepartment(@RequestBody @Validated(Update.class) SysDepartment sysDepartment) {
        return sysDepartmentService.updateSysDepartment(sysDepartment) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "修改部门信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "修改部门信息失败");
    }

    /**
     * 获取部门信息 (所有)
     *
     * @param sysDepartmentQuery
     * @return
     */
    @ApiOperation("获取部门信息 (所有)")
    @GetMapping("/getSysDepartmentList")
    public CommonResultRes<List<SysDepartmentVo>> getSysDepartmentList(SysDepartmentQuery sysDepartmentQuery) {
        return new CommonResultRes<>(sysDepartmentService.getSysDepartmentList(sysDepartmentQuery));
    }

    /**
     * 获取部门信息 (详情)
     *
     * @param departmentId
     * @return
     */
    @ApiOperation("获取部门信息 (详情)")
    @GetMapping("/getSysDepartment/{departmentId}")
    public CommonResultRes<SysDepartment> getSysDepartment(@Validated @PathVariable Integer departmentId) {
        return new CommonResultRes<>(sysDepartmentService.getSysDepartment(departmentId));
    }

}
